﻿Public Class FormGjbInfoList
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Dim objGJBinfo As New clsGJBinfo
    Dim objLog As New clsLog
    Private Sub FormGjbInfoList_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        txt_dl_no.Focus()
    End Sub

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        If String.IsNullOrEmpty(txt_dl_no.Text.Trim) = False Then
            search()
        End If
    End Sub

    Private Sub search()
        If String.IsNullOrEmpty(txt_dl_no.Text.Trim()) = False Then
            txt_dl_no.Text = txt_dl_no.Text.ToUpper()
            Dim dt As DataTable = objGJBinfo.getListsByDlNo(txt_dl_no.Text.Trim())
            dt.Columns.Add("status_name")
            If dt.Rows.Count > 0 Then
                For Each row As DataRow In dt.Rows
                    If row("status") = "0" Then
                        row("status_name") = "未使用"
                    Else
                        row("status_name") = "已使用"
                    End If
                Next
            End If
            dgv.AutoGenerateColumns = False
            dgv.DataSource = dt
        Else
            MsgBox("请输入骨架板吊篮号", vbYes, "提示")
        End If
    End Sub

    Private Sub dgv_SelectionChanged(sender As Object, e As EventArgs) Handles dgv.SelectionChanged
        If dgv.SelectedRows.Count > 0 Then
            txtNum.Value = dgv.SelectedRows(0).Cells("layer_num").Value.ToString()
            txtWeight.Value = dgv.SelectedRows(0).Cells("wt").Value.ToString()
        End If
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If dgv.SelectedRows.Count > 0 Then
            If dgv.SelectedRows(0).Cells("Col_status").Value.ToString().Equals("0") Then
                Dim sys_id As String = dgv.SelectedRows(0).Cells("sys_id").Value.ToString()
                Dim rtn As Integer = objGJBinfo.save(txtNum.Text.Trim(), txtWeight.Text.Trim(), sys_id)
                If rtn <> -2 Then
                    MsgBox("保存成功！", vbYes, "提示")
                    objLog.insert("骨架板吊篮", "骨架板板完成数量", "骨架板吊篮sys_id：" & sys_id & "，片数改为：" & txtNum.Text.Trim() & "，重量改为：" & txtWeight.Text.Trim())
                    search()
                Else
                    MsgBox("保存失败！", vbYes, "提示")
                End If
            Else
                MsgBox("该骨架板料框为已使用状态，无法进行修改保存", vbYes, "提示")
            End If
        Else
            MsgBox("请选择需要修改的吊篮！", vbYes, "提示")
        End If
    End Sub

    Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
        If dgv.SelectedRows.Count > 0 Then
            If dgv.SelectedRows(0).Cells("Col_status").Value.ToString().Equals("0") Then
                If MsgBox("确认删除吗？", vbYesNo, "提示") = vbYes Then
                    Dim sys_id As String = dgv.SelectedRows(0).Cells("sys_id").Value.ToString()
                    Dim dl_no As String = dgv.SelectedRows(0).Cells("dl_no").Value.ToString()
                    Dim rtn As Integer = objGJBinfo.saveDelete(dl_no, sys_id)
                    If rtn <> -2 Then
                        MsgBox("删除成功！", vbYes, "提示")
                        objLog.insert("骨架板吊篮", "骨架板吊篮删除", "骨架板吊篮sys_id：" & sys_id & "，删除了")
                        search()
                    Else
                        MsgBox("删除失败！", vbYes, "提示")
                    End If
                End If
            Else
                MsgBox("当前吊篮信息已使用，无法进行删除！", vbYes, "提示")
            End If
        Else
            MsgBox("请选择需要删除的吊篮！", vbYes, "提示")
        End If
    End Sub

    Private Sub btnUpdateStatus2Used_Click(sender As Object, e As EventArgs) Handles btnUpdateStatus2Used.Click
        If dgv.SelectedRows.Count > 0 Then
            If dgv.SelectedRows(0).Cells("Col_status").Value.ToString().Equals("0") Then
                If MsgBox("确认置为已使用吗？", vbYesNo, "提示") = vbYes Then
                    Dim sys_id As String = dgv.SelectedRows(0).Cells("sys_id").Value.ToString()
                    Dim rtn As Integer = objGJBinfo.saveUpdateStatus(sys_id)
                    If rtn <> -2 Then
                        MsgBox("置为已使用成功！", vbYes, "提示")
                        objLog.insert("骨架板吊篮", "骨架板吊篮置为已使用", "骨架板吊篮sys_id：" & sys_id & "，置为已使用了")
                        search()
                    Else
                        MsgBox("置为已使用失败！", vbYes, "提示")
                    End If
                End If
            Else
                MsgBox("当前吊篮信息已使用，无法操作！", vbYes, "提示")
            End If
        Else
            MsgBox("请选择需要置为已使用的吊篮！", vbYes, "提示")
        End If
    End Sub

    Private Sub txtNum_MouseDown(sender As Object, e As MouseEventArgs) Handles txtNum.MouseDown
        sender.Focus
        UcDigitalKeyboard1 = New ucDigitalKeyboard

        UcDigitalKeyboard1.B_01 = False
        UcDigitalKeyboard1.B_02 = False

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()

    End Sub
    Private Sub txtWeight_MouseDown(sender As Object, e As MouseEventArgs) Handles txtWeight.MouseDown
        sender.Focus
        UcDigitalKeyboard1 = New ucDigitalKeyboard

        UcDigitalKeyboard1.B_01 = True
        UcDigitalKeyboard1.B_02 = False

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()

    End Sub
    Private Sub ucdigitalkeyboard1_leave(sender As Object, e As EventArgs) Handles UcDigitalKeyboard1.Leave
        UcDigitalKeyboard1.Dispose()
    End Sub

End Class